From d09980b3f466416055a4e4841ab2946c079f386f Mon Sep 17 00:00:00 2001 From: robertlipe Date: Tue, 27 Jan 2015 04:33:45 +0000 Subject: [PATCH] Minor doc improvements on our hodgepodge of C89 and Qt. Whitespace changes, mostly trailing whitespace. --- gpsbabel/README.contrib | 26 +++++++++++++++----------- gpsbabel/html.cc | 4 ++-- gpsbabel/humminbird.cc | 6 +++--- gpsbabel/mkshort.cc | 2 +- gpsbabel/mmo.cc | 9 +++++---- gpsbabel/mynav.cc | 35 ++++++++++++++++++++++------------- gpsbabel/navilink.cc | 2 +- gpsbabel/osm.cc | 2 +- gpsbabel/tomtom.cc | 3 ++- gpsbabel/transform.cc | 2 +- gpsbabel/unicsv.cc | 6 +++--- gpsbabel/util.cc | 12 ++++++------ gpsbabel/waypt.cc | 6 +++--- 13 files changed, 65 insertions(+), 50 deletions(-) diff --git a/gpsbabel/README.contrib b/gpsbabel/README.contrib index 3f865f2b0..17ac821ac 100644 --- a/gpsbabel/README.contrib +++ b/gpsbabel/README.contrib @@ -12,17 +12,20 @@ functions. You may find format_skeleton.c and filter_skeleton.c in the source tree to be helpful examples. Just add meat! -Prefer Qt objects/classes to ISO C/POSIX services. QStrings are reference -counted, implicitly shared, and have a robust supporting library. QDateTime -supports sub-second time and a range of dates far beyond 1970->2038 and are -much more pleasant to work with than ctime/mktime/struct tm. "But I see -strcpy, sprintf, and struct tm and such in the code!" It's true; GPSBabel -is a tenured project of well over ten years. We have code that predates -our move to C++/Qt that isn't well tested or has a low payoff to modernize -and uses old constructs. Our actively maintained/strategic formats like -GPX and KML tend to be better examples of modern programming, using things -like XmlStreamWriter instead of fprintf and are generally better models to -follow. +Prefer Qt objects/classes to ISO C/POSIX services. + * QStrings are reference counted, implicitly shared, and have a + robust supporting library. + * QDateTime supports sub-second time and a range of dates far + beyond 1970->2038 and are much more pleasant to work with + than ctime/mktime/struct tm. + * QXmlStreamReader and Writer eliminate the need to explictly quote data. +"But I see strcpy, sprintf, and struct tm and such in the code!" It's +true; GPSBabel is a tenured project of well over ten years. We have +code that predates our move to C++/Qt that isn't well tested or has a +low payoff to modernize and uses old constructs. Our actively +maintained/strategic formats like GPX and KML tend to be better +examples of modern programming and are generally better models to +follow. New code shouldn't be using xstrdup and gbfprintf. Compilers complain for a reason. Code shouldn't emit warnings. @@ -37,6 +40,7 @@ prefer: int mumble(int whatever) { + <2spaces>char* pointers_clump_to_type; <2spaces>if (whatevever) { <4spaces>return blah; <2spaces>} diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index f208e7cb4..91b52a663 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -258,10 +258,10 @@ data_write(void) gbfprintf(file_out, "\n"); gbfprintf(file_out, " \n"); - // Don't write this line when running test suite. Actually, we should + // Don't write this line when running test suite. Actually, we should // probably not write this line at all... if (!getenv("GPSBABEL_FREEZE_TIME")) { - gbfprintf(file_out, " \n", gpsbabel_version); + gbfprintf(file_out, " \n", gpsbabel_version); } gbfprintf(file_out, " GPSBabel HTML Output\n"); if (stylesheet) { diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index b9380230a..3d70ebcfd 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -286,7 +286,7 @@ humminbird_read_wpt(gbfile* fin) wpt = new Waypoint; // Could probably find a way to eliminate the alloc/copy. - char *s = xstrndup(w.name, sizeof(w.name)); + char* s = xstrndup(w.name, sizeof(w.name)); wpt->shortname = s; xfree(s); @@ -361,7 +361,7 @@ humminbird_read_route(gbfile* fin) rte = route_head_alloc(); route_add_head(rte); // TODO: find a way to eliminate the copy. - char *s = xstrndup(hrte.name, sizeof(hrte.name)); + char* s = xstrndup(hrte.name, sizeof(hrte.name)); rte->rte_name = s; xfree(s); /* rte->rte_num = hrte.num + 1; only internal number */ @@ -429,7 +429,7 @@ humminbird_read_track(gbfile* fin) track_add_head(trk); // TODO: find a way to eliminate the copy. - char *s = xstrndup(th.name, sizeof(th.name)); + char* s = xstrndup(th.name, sizeof(th.name)); trk->rte_name = s; xfree(s); trk->rte_num = th.trk_num; diff --git a/gpsbabel/mkshort.cc b/gpsbabel/mkshort.cc index e7ffec151..aa75e7f18 100644 --- a/gpsbabel/mkshort.cc +++ b/gpsbabel/mkshort.cc @@ -577,7 +577,7 @@ mkshort(short_handle h, const char* istring) QString mkshort(short_handle h, const QString& istring) { - char *t = mkshort(h, CSTR(istring)); + char* t = mkshort(h, CSTR(istring)); QString r(t); xfree(t); return r; diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index d3fe913d1..f2d071f04 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -313,7 +313,7 @@ mmo_free_object(mmo_data_t* data) xfree(data->name); } if ((data->type == wptdata) && (data->refct == 0)) { - delete (Waypoint*)data->data; + delete(Waypoint*)data->data; } xfree(data); } @@ -945,7 +945,7 @@ mmo_finalize_rtept_cb(const Waypoint* wptref) mmo_data_t* data; Waypoint* wpt2; -// This code path isn't tested in anything we have and I have No Idea +// This code path isn't tested in anything we have and I have No Idea // what it was trying to do. Throw a hard error to force the hand of // getting a sample file. abort(); @@ -1122,7 +1122,8 @@ mmo_writestr(const char* str) } static void -mmo_writestr(const QString& str) { +mmo_writestr(const QString& str) +{ // If UTF-8 is used instgead of Latin1, we fail in weird ways. mmo_writestr(str.toLatin1().constData()); } @@ -1214,7 +1215,7 @@ mmo_write_obj_head(const char* sobj, const char* name, const time_t ctime, static void mmo_write_wpt_cb(const Waypoint* wpt) { - QString str; + QString str; QString cx; int objid; time_t time; diff --git a/gpsbabel/mynav.cc b/gpsbabel/mynav.cc index 62576d08f..3a660c551 100644 --- a/gpsbabel/mynav.cc +++ b/gpsbabel/mynav.cc @@ -3,7 +3,7 @@ Copyright (c) 2014 Ralf Horstmann Copyright (C) 2014 Robert Lipe, robertlipe+source@gpsbabel.org - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -58,36 +58,43 @@ mynav_rd_line(QString line) if (global_opts.debug_level > 1) { qDebug() << "line: " << line; - for (int i = 0; i < fields.size(); i++) + for (int i = 0; i < fields.size(); i++) { qDebug() << "field" << i << fields.at(i); + } } // don't consider lines without latitude/longitude - if (fields.size() <= fld_lat) + if (fields.size() <= fld_lat) { return; + } // only type 1 and type 5 lines contain coordinates bool ok = false; - int val_type = fields.at(fld_type).trimmed().toInt(&ok); - if (!ok) + int val_type = fields.at(fld_type).trimmed().toInt(&ok); + if (!ok) { return; - if (val_type != 1 && val_type != 5) + } + if (val_type != 1 && val_type != 5) { return; + } // This field is not present in .trc files, only in .ftn, so // ignore line if present and != 1 if (fields.size() > fld_gps_valid) { int val_gps_valid = fields.at(fld_gps_valid).trimmed().toInt(&ok); - if (!ok || val_gps_valid != 1) + if (!ok || val_gps_valid != 1) { return; + } } double val_lon = fields.at(fld_lon).trimmed().toDouble(&ok) / 3600000.0; - if (!ok) + if (!ok) { return; + } double val_lat = fields.at(fld_lat).trimmed().toDouble(&ok) / 3600000.0; - if (!ok) + if (!ok) { return; + } Waypoint* wpt = new Waypoint; wpt->latitude = val_lat; @@ -95,16 +102,18 @@ mynav_rd_line(QString line) if (fields.size() > fld_altitude) { double val_alt = fields.at(fld_altitude).trimmed().toDouble(&ok); - if (ok) + if (ok) { wpt->altitude = val_alt; + } } if (fields.size() > fld_timestamp) { int val_time = fields.at(fld_timestamp).trimmed().toInt(&ok); - if (ok) + if (ok) { wpt->SetCreationTime(val_time); + } } - + track_add_wpt(mynav_track, wpt); } @@ -127,7 +136,7 @@ mynav_rd_deinit(void) gbfclose(fin); } -static void +static void mynav_rd(void) { QString buff; diff --git a/gpsbabel/navilink.cc b/gpsbabel/navilink.cc index 0139c4a26..c586c6570 100644 --- a/gpsbabel/navilink.cc +++ b/gpsbabel/navilink.cc @@ -847,7 +847,7 @@ navilink_decode_logpoint(const unsigned char* buffer) waypt->hdop = ((unsigned char)buffer[0]) * 0.2f; waypt->sat = buffer[1]; - waypt->SetCreationTime(decode_sbp_datetime_packed(buffer + 4), + waypt->SetCreationTime(decode_sbp_datetime_packed(buffer + 4), decode_sbp_msec(buffer + 2)); decode_sbp_position(buffer + 12, waypt); WAYPT_SET(waypt, speed, le_read16(buffer + 24) * 0.01f); diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index c8699781b..d5f91c86d 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -631,7 +631,7 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv) rte->rte_name = str; wpt->shortname = str; - // The remaining cases only apply to the center node + // The remaining cases only apply to the center node } else if ((ikey = osm_feature_ikey(key)) >= 0) { wpt->icon_descr = osm_feature_symbol(ikey, CSTR(value)); } else if (key == "note") { diff --git a/gpsbabel/tomtom.cc b/gpsbabel/tomtom.cc index ce9cc786a..2247b215e 100644 --- a/gpsbabel/tomtom.cc +++ b/gpsbabel/tomtom.cc @@ -356,7 +356,8 @@ write_blocks(gbfile* f, struct blockheader* blocks) static struct blockheader* compute_blocks(struct hdr* start, int count, - double minlon, double maxlon, double minlat, double maxlat) { + double minlon, double maxlon, double minlat, double maxlat) +{ struct blockheader* newblock; newblock = (struct blockheader*)xcalloc(sizeof(*newblock), 1); diff --git a/gpsbabel/transform.cc b/gpsbabel/transform.cc index c625ed974..1fa9b7de5 100644 --- a/gpsbabel/transform.cc +++ b/gpsbabel/transform.cc @@ -114,7 +114,7 @@ transform_rte_disp_hdr_cb(const route_head* rte) if (current_target == 'T') { current_trk = route_head_alloc(); track_add_head(current_trk); - if (!rte->rte_name.isEmpty()) { + if (!rte->rte_name.isEmpty()) { current_trk->rte_desc = QString("Generated from route %1").arg(rte->rte_name); current_trk->rte_name = rte->rte_name; /* name the new trk */ } diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 016cea94a..b6723917e 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -307,7 +307,7 @@ unicsv_parse_gc_id(const QString& str) int res = 0; const QString kBase35 = "0123456789ABCDEFGHJKMNPQRTVWXYZ"; // ILOSU are omitted. if (str.startsWith("GC")) { - int base35 = str.size() > 6; // above GCFFFF? + int base35 = str.size() > 6; // above GCFFFF? QString s = str.mid(2); while (!s.isEmpty()) { res = res * 16 + kBase35.indexOf(s[0]); @@ -429,7 +429,7 @@ unicsv_parse_status(const QString& str) str == "0") { return status_false; } -return status_unknown; + return status_unknown; } static QDateTime @@ -628,7 +628,7 @@ unicsv_parse_one_line(char* ibuf) double swiss_easting = unicsv_unknown; double swiss_northing = unicsv_unknown; int checked = 0; - time_t date = -1; + time_t date = -1; time_t time = -1; int usec = -1; char is_localtime = 0; diff --git a/gpsbabel/util.cc b/gpsbabel/util.cc index 214fd1f59..4058eeff4 100644 --- a/gpsbabel/util.cc +++ b/gpsbabel/util.cc @@ -284,7 +284,7 @@ xasprintf(QString* strp, const char* fmt, ...) va_list args; int res; va_start(args, fmt); - char *cstrp; + char* cstrp; res = xvasprintf(&cstrp, fmt, args); *strp = cstrp; xfree(cstrp); @@ -533,7 +533,7 @@ str_match(const char* str, const char* match) if (*m == '\0') { return 0; /* incomplete escape sequence */ } - /* pass-through next character */ + /* pass-through next character */ default: if (*m != *s) { @@ -783,7 +783,7 @@ mkgmtime(struct tm* t) result += t->tm_min; result *= 60; result += t->tm_sec; - return(result); + return (result); } /* @@ -1174,7 +1174,7 @@ rot13(const QString& s) static const QChar Z('Z'); QString r = s; int i = r.length(); - while(i--) { + while (i--) { QChar letter = r[i].toUpper(); if (letter >= A && letter <= M) { r[i] = QChar(r[i].toLatin1() + 13); @@ -1493,10 +1493,10 @@ strip_html(const utf_string* in) { #if 0 // If we were willing to link core against QtGui (not out of the question) - // we could just do...and either decide whether to add handling for [IMG] + // we could just do...and either decide whether to add handling for [IMG] // or just say we don't do that any more. QTextDocument doc; - doc.setHtml( in->utfstring ); + doc.setHtml(in->utfstring); return xstrdup(CSTR(doc.toPlainText().simplified())); #else char* outstring, *out; diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index aa80eb11a..3cdbcdbe0 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -100,11 +100,11 @@ waypt_add(Waypoint* wpt) } if ((wpt->latitude < -90) || (wpt->latitude > 90.0)) - Fatal() << wpt->session->name - << "Invalid latitude" << lat_orig << "in waypoint" + Fatal() << wpt->session->name + << "Invalid latitude" << lat_orig << "in waypoint" << wpt->shortname; if ((wpt->longitude < -180) || (wpt->longitude > 180.0)) - Fatal() << "Invalid longitude" << lon_orig << "in waypoint" + Fatal() << "Invalid longitude" << lon_orig << "in waypoint" << wpt->shortname; /* -- 2.30.2